JavaScript

toFormat Method

Syntax

dateStr = d.toFormat(dateFormat)

Arguments

dateFormatstring

Defines the format of the generated date string. The date format can use the following directives:

Directive
Description
0

Format element (causes a time element h, m, or s, to be returned with a leading 0) - Example: 0h:0m:0s

s

Second

m

Minute

h

Hour

am

12 hour clock with "am" or "pm" suffix

A

12 hour clock with "A" or "P" suffix

AM

12 hour clock with "AM" or "PM" suffix

d

day (one digit) 3

dd

day spelled out (two digits, 0 pad) 03, 15

M

month (one digit) 1

MM

month (two digits, zero pad) 01, 10

MON

month (three character name, upper case) JAN, FEB

mon

month (three character name, lower case) jan, feb

Mon

month (three character name, proper case) Jan, Feb

MONTH

month (full name, upper case) JANUARY, FEBRUARY

month

month (full name, lower case) january, february

Month

month (full name, proper case) e.g. January, February

y

year (two digits) 99, 03

yy

year (two digits) 99, 03

yyyy

year (four digits) 1999, 2003

Description

Generates a formatted string from a Date.

Example

var d = new Date();
    alert(d.toFormat('dd-Mon-yyyy');